<template>
  <view>
    <!-- 选择收货地址的盒子 -->
    <view class="address-choose-box" v-if="JSON.stringify(address)==='{}'">
      <button type="primary" size="mini" class="btnChooseAddress" @click="chooseAddress">请选择收货地址+</button>
    </view>
    <!-- 选择收货地址的盒子结束 -->
    <!-- 渲染选择的收货信息盒子 -->
    <view class="address-info-box" v-else @click="chooseAddress">
      <view class="wrap1">
        <view class="wrap1-left">
          <view class="username">
            收货人:<text>{{address.userName}}</text>
          </view>
        </view>
        <view class="wrap1-right">
          <view class="tel">
            电话:<text>{{address.telNumber}}</text>
            <uni-icons class="qtIcon" type="arrowright" size="16"></uni-icons>
          </view>
        </view>

      </view>
      <view class="wrap2">
        <view class="wrap2-left">
          收货地址:
        </view>
        <view class="wrap2-right">
         {{addstr}}
        </view>
      </view>
    </view>
    <!-- 渲染选择的收货信息盒子结束 -->
    <image class="address-border" src="../../static/address.png"></image>
  </view>
</template>

<script>
  import {mapState,mapMutations,mapGetters } from 'vuex'
  export default {
    name: "my-address",
    data() {
      return {
        
      };
    },
    computed:{
      ...mapState('m_user',['address']),
      ...mapGetters('m_user',['addstr']),
 
    },
    methods: {
      ...mapMutations('m_user',['updateAddress']),
      // 选择收货地址
      async chooseAddress() {
        const [err, succ] = await uni.chooseAddress().catch(err => err)
        console.log(err);
        console.log(succ);
        if (err === null && succ.errMsg === 'chooseAddress:ok') {
          // this.address=succ
          this.updateAddress(succ)
        }
      }
    }
  }
</script>

<style lang="scss">
  .address-border {
    display: block;
    width: 100%;
    height: 5px;

  }

  .address-choose-box {
    display: flex;
    height: 100px;
    justify-content: center;
    align-items: center;

    .btnChooseAddress {}
  }

  .address-info-box {
    padding: 0 10rpx;
    font-size: 24rpx;
    display: flex;
    flex-direction: column;

    .wrap1 {
      padding: 20rpx 0;
      display: flex;
      justify-content: space-between;
      align-items: center;

      .wrap1-left {
        .username {
          text {
            margin-left: 10rpx;
          }
        }
      }

      .wrap1-right {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text{
          padding-left: 10rpx;
        }
        .qtIcon {
          padding: 0 0 0 20rpx;
        }
      }
    }

    .wrap2 {
      padding: 10rpx 0 20rpx 0;
      display: flex;
      align-items: center;

      .wrap2-right {
        margin: 10rpx;
      }
    }
  }
</style>
